<?php
defined('IN_IA') or exit('Access Denied');
global $_GPC, $_W;
$uniacid = $_W['uniacid'];
$id = $_GPC['id'];
$op = $_GPC['op'];
if (empty($op)) {
	$op == 'add';
}
load()->func('tpl');
$set = pdo_fetch('SELECT * FROM ' . tablename($this->tableuser) . ' WHERE uniacid = :uniacid AND id = :id', array(':uniacid' => $uniacid, ':id' => $id));
if (!empty($set['openid'])) {
	load()->model('mc');
	$mcinfo = mc_fansinfo($set['openid']);
	$avatar = $mcinfo['avatar'];
	$nickname = $mcinfo['nickname'];
	$nickname = json_encode($nickname);
	$nickname = preg_replace("#(\\\u[ed][0-9a-f]{3})#ie", "", $nickname);
	$nickname = json_decode($nickname);
}
if (checksubmit('submit')) {
	$data = array('uniacid' => $uniacid, 'status' => trim($_GPC['status']), 'uid' => trim($_GPC['uid']), 'openid' => trim($_GPC['openid']), 'nickname' => trim($_GPC['nickname']), 'avatar' => trim($_GPC['avatar']), 'displayorder' => trim($_GPC['displayorder']), 'ctime' => strtotime($_GPC['ctime']), 'vtime' => strtotime($_GPC['vtime']),);
	if ($op == 'add' && empty($set)) {
		pdo_insert($this->tableuser, $data);
	}
	if ($op == 'edit' && !empty($set)) {
		pdo_update($this->tableuser, $data, array('id' => $set['id']));
	}
	message('数据操作成功！', 'refresh');
}
if ($op != 'del') {
	include $this->template('listuser_add');
}